package org.cicd.utils;

import org.cicd.enums.OSType;

/**
 * 操作系统类型判断
 */
class OSUtils {

    static String OS = System.getProperty("os.name").toLowerCase();

    static OSUtils _instance = new OSUtils();

    OSType osType;

    OSUtils() {}

    /**
     * 判断是否为 Linux
     * @return
     */
    static boolean isLinux() {
        return OS.indexOf("linux")>=0;
    }

    /**
     * 判断是否为 MacOS
     *
     * @return
     */
    static boolean isMacOS() {
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")<0;
    }

    /**
     * 判断是否为 MacOSX
     * @return
     */
    static boolean isMacOSx() {
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")>0;
    }

    /**
     * 判断是否为 windows 操作系统
     *
     * @return
     */
    static boolean isWindows() {
        return OS.indexOf("windows")>=0;
    }

    static OSType getOSType() {
        if(isLinux()) {
            _instance.osType =  OSType.Linux;
        }
        if(isMacOS()) {
            _instance.osType =  OSType.Mac_OS;
        }
        if (isMacOSx()) {
            _instance.osType =  OSType.Mac_OS_X;
        }
        if(isWindows()) {
            _instance.osType =  OSType.Windows;
        }
        return _instance.osType;
    }

    static void main(String[] args) {
        def log = new log();
        log.info(isWindows());
    }
}
